using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using BTV.Base;
using TVAnyTimeClassLibrary;

namespace BTV.TVAnyTime
{
    public class TVAnyProgram : BTVProgram
    {
        private List<string> _promo = new List<string>();

        private int _relatedScore;

        public int RelatedScore
        {
            get { return _relatedScore; }
            set { _relatedScore = value; }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public List<string> Promo
        {
            get { return _promo; }
        }
        private List<GenreType> _genres = new List<GenreType>();

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public List<GenreType> Genres
        {
            get { return _genres; }
        }

        public TVAnyProgram(string pid)
        {
            this.PID = pid;
        }

        public TVAnyProgram()
        {
        }

        public void AddPromotionalInfo(string data)
        {
            _promo.Add(data);
        }

        public void AddGenre(GenreType genre)
        {
            Genres.Add(genre);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public bool HasGenre(GenreType genre)
        {
            foreach (GenreType g in Genres)
            {
                if (g.Name.Value.Equals(genre.Name.Value))
                    return true;
            }
            return false;
        }

        public int RelatedGenreScore(TVAnyProgram program)
        {
            int score = 0;
            foreach (GenreType g in program.Genres)
            {
                if (this.HasGenre(g))
                    score++;
            }
            this.RelatedScore = score;
            return score;
        }

        private List<KeywordType> _keywords = new List<KeywordType>();

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public List<KeywordType> Keywords
        {
            get { return _keywords; }
        }

        public void AddKeyword(KeywordType kw)
        {
            Keywords.Add(kw);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public bool HasKeyword(KeywordType kw)
        {
            foreach (KeywordType key in Keywords)
            {
                if (key.Value.Equals(kw.Value))
                    return true;
            }
            return false;
        }

        private List<SynopsisType> _synopsis = new List<SynopsisType>();

        public override void AddSynopsis(object a, object b)
        {
            _synopsis.Add(a as SynopsisType);
        }

        public override string GetLongSynopsis(bool tryShort)
        {
            foreach(SynopsisType syn in _synopsis)
                if (syn.length.ToString().ToLower().Equals("long"))
                    return syn.Value.Replace("\n", System.Environment.NewLine);
            if (tryShort)
            {
                return GetShortSynopsis(false);
            }
            return "No Synopsis Available";
        }

        public override string GetShortSynopsis(bool tryLong)
        {
            foreach (SynopsisType syn in _synopsis)
                if (syn.length.ToString().ToLower().Equals("short"))
                    return syn.Value.Replace("\n", System.Environment.NewLine);
            if (tryLong)
            {
                return GetLongSynopsis(false);
            }
            return "No Synopsis Available";
        }
    }
}